home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 26.zip
/
BS1 part 26
/
C for beginners.adf
/
source
/
itoa.c
< prev
next >
Wrap
C/C++ Source or Header
|
1978-01-17
|
1KB
|
56 lines
#include "stringfunc.c"
/*****************************************/
/* Name: itoa */
/* Parameter: n(int), s(string) */
/* function: Convert Integer to string */
/* comment: Requires reverse() */
/*****************************************/
#define EOS '0'
#define FALSE 0
#define TRUE 1
itoa(n, s)
register int n;
register char *s;
{
register int i = 0;
register int sign = FALSE;
if(n < 0)
{
sign = TRUE;
n = -n;
}
do
s[i++] = n % 10 + '0';
while(n /=10);
if(sign)
s[i++] = '-';
s[i] = EOS;
reverse(s);
}
/****************************************/
/* Name: reverse */
/* Parameter: s(string) */
/* function: Reverse string */
/* comment: Requires strlen() */
/****************************************/
reverse(s)
register char *s;
{
register int c, i, j;
for(i=0, j = strlen(s) - 1; i < j; i++, j--)
{
c = s[i];
s[i] = s[j];
s[j] = c;
}
}